//
//  CalenderManager.m
//  PeitaMerchants
//
//  Created by apple on 17/5/12.
//  Copyright © 2017年 Facebook. All rights reserved.
//

#import "CommonModule.h"

@implementation CommonModule

// 为了实现RCTBridgeModule协议，你的类需要包含RCT_EXPORT_MODULE()宏。这个宏也可以添加一个参数用来指定在Javascript中访问这个模块的名字。如果你不指定，默认就会使用这个Objective-C类的名字。

RCT_EXPORT_MODULE(CommonModule);


//  对外提供调用方法（testNormalEvent为方法名，后面为参数，按顺序和对应数据类型在js进行传递）

// 个推cid
RCT_EXPORT_METHOD(getCid:(RCTResponseSenderBlock)callback) {
  
  
  NSLog(@"回调个推啦%@",[[NSUserDefaults standardUserDefaults] objectForKey:@"clientID"]);
  callback([[NSUserDefaults standardUserDefaults] objectForKey:@"clientID"]);
  
}

// 获取融云token 连接融云
RCT_EXPORT_METHOD(getRongToken:(NSString *)accessToken userID:(NSString *)userId userName:(NSString *)userName userIcon:(NSString *)userIcon) {
  
  NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
  [dataDict setObject:accessToken forKey:@"accessToken"];
  [dataDict setObject:userId forKey:@"userId"];
  [dataDict setObject:userName forKey:@"userName"];
  [dataDict setValue:userIcon forKey:@"userIcon"];
  
  [[NSUserDefaults standardUserDefaults] setObject:accessToken forKey:@"accessToken"];
  [[NSUserDefaults standardUserDefaults] setObject:userId forKey:@"userId"];
  
  [[NSUserDefaults standardUserDefaults] synchronize];
  
  
  NSLog(@"接收到连接融云啦%@",dataDict);
  
  [[NSNotificationCenter defaultCenter] postNotificationName:@"connectRC" object:dataDict];
  
}

// 打开聊天界面 ( 1单聊 or 0群聊)
RCT_EXPORT_METHOD(startChat:(BOOL)isPrivate userId:(NSString *)userId userName:(NSString *)userName) {
  
  NSDictionary *dataDict = @{@"status":@(isPrivate),@"userId":userId,@"userName":userName};
  [[NSNotificationCenter defaultCenter] postNotificationName:@"openChat" object:dataDict];
  
  
  NSLog(@"打开聊天界面啦%@",dataDict);
  
}

@end
